﻿using System;
using System.Collections.Generic;

namespace WebTest.Core.Entities
{
    public class Role : BaseEntity
    {
        /// <summary>
        /// 角色名称
        /// </summary>
        public string Name { get; private set; }
        private readonly List<Member> _members = new List<Member>();
        /// <summary>
        /// 属于该角色的所有会员
        /// </summary>
        public IEnumerable<Member> Members
        {
            get
            {
                return _members;
            }
        }

        public Role(string name)
        {
            Name = name ?? throw new ArgumentNullException(nameof(name));
        }
        /// <summary>
        /// 添加会员
        /// </summary>
        /// <param name="member"></param>
        public void AddMember(Member member)
        {
            if (!_members.Exists(x => x.Account == member.Account))
            {
                _members.Add(member);
            }
        }
        public void RemoveMember(Member member)
        {
            if (_members.Exists(x => x.Account == member.Account))
            {
                _members.Remove(member);
            }
        }
    }
}
